const apiList = {
  queryPsbzfllb: "fwd/queryPsbzfllb",
  queryPsbzlb: "fwd/queryPsbzlb",
  queryRylb: "fwd/queryRylb",
  addDmzc: "fwd/addDmzc",
  addJhdmzc: "fwd/addJhdmzc",

  getGcxx: "khd/getGcxx",
}
let host = location.origin
// host = "http://localhost:9999"

axios.defaults.baseURL = host

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  let data = response.data
  if (data.code !== 0) {
    return Promise.reject(new Error(data.message));
  }
  return data.data;
}, function (error) {
  let response = error.response
  if (response) {
    if (response.data) {
      return Promise.reject(new Error(response.data.message));
    }
  }
  return Promise.reject(error);
});

Vue.prototype.$api = new Proxy({}, {
  get(target, p, receiver) {
    return (data, config = {}) => {
      return axios.post(apiList[p], data, {
        headers: {
          "tf-token": sessionStorage.getItem("token")
        },
        ...config
      })
    }
  }
})
